<template>
  <div id="warehouse" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" :title="$t('config.wareSetting')"></v-tableTitle>
    <v-table :pageSize="pageSize" :page="page" :tableConfig="tableConfig" :tableData="tableData" :total="total" @findData="getTableData" @getTableData="getTableData" @searhData="searhData"
      @selectData="selectData" @setdialog="setdialog" @upData="getTableData" ref="table"></v-table>
    <el-dialog :modal="false" :visible.sync="dialogFlag" title="" top="0" v-dialogDrag :close-on-click-modal="false" width="900px">
      <router-view></router-view>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from 'commons/TableTitle'
import table from 'commons/Table'
import baseMixin from '@/mixins/BaseMixin'
import config from './Config'

export default {
  name: 'warehouse',
  mixins: [baseMixin, config],
  data() {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('outbound.db_logid'),
          prop: 'db_logid',
          input: 'input'
        },
        {
          label: this.$t('config.wareName'),
          prop: 'db_alias',
          input: 'input'
        },
        {
          label: this.$t('config.activityStatus'),
          prop: 'isactive',
          input: 'select',
          options: [
            { code: '1', description: this.$t('code.yes') },
            { code: '0', description: this.$t('code.no') }
          ]
        },
        {
          label: this.$t('outbound.db_locationnounid'),
          prop: 'db_locationnounid',
          input: 'input'
        }
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
      dialogFlag: false
    }
  },
  computed: {
    btnConfig() {
      return []
    }
  },
  created() {},
  methods: {
    //选中的内容
    selectData(data) {
      this.tableSelectData = data
    },
    async getTableData(page, data) {
      try {
        this.loading = true
        let res = await this.$api.post(`/queryWareHouseList/${page}`, data)
        
          this.tableData = res.page.list
          this.page = res.page.curpage
          this.pageSize = res.page.pageSize
          this.total = res.page.total
        
      } catch (e) {
        this.$message.error(error)
      } finally {
        this.loading = false
      }
    },
    //设置弹框
    setdialog(data) {
      this.$store.commit('setRouteData', data)
      this.dialogFlag = true
      setTimeout(() => {
        this.$router.push({ name: 'warehouseDeawer' })
      }, 0)
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data
      } else {
        this.tableSearhData = data
        this.getTableData(1, this.tableSearhData)
      }
    }
  },
  mounted() {
    
    this.$store.commit('setSkip', {})
    this.$store.commit('setNewFlag', false)
    this.$store.commit('setRouteData', {})
    this.getTableData(1, {})
  },
  watch: {
    $route(data) {
      if (data.name === 'warehouse') {
        this.dialogFlag = false
      }
    },
    dialogFlag(data) {
      if (data === false) {
        this.$store.commit('setNewFlag', false)
        this.getTableData(1, {})
        this.$router.push({ name: 'warehouse' })
        this.$store.commit('setSkip', {})
        this.$store.commit('setRouteData', {})
      }
    }
  },
  components: {
    'v-tableTitle': tableTitle,
    'v-table': table
  }
}
</script>

<style scoped>
#warehouse {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
